package com.corechina.apex_osswords.domain.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.corechina.apex_osswords.domain.entity.CoreEnterprise;
import com.corechina.apex_osswords.domain.entity.CoreEnterpriseEngineer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 企业--运维表 Mapper 接口
 * </p>
 *
 * @author cc
 * @since 2022-12-26
 */
@Component
public interface CoreEnterpriseEngineerMapper extends BaseMapper<CoreEnterpriseEngineer> {

    @Select("select count(1) from core_enterprise_engineer where enterprise_id = #{enterpriseId} and engineer_id = #{engineerId}")
    int checkEngineer(@Param("enterpriseId") Integer enterpriseId, @Param("engineerId") Integer engineerId);

    @Delete("delete from core_enterprise_engineer where enterprise_id = #{enterpriseId} and engineer_id = #{engineerId}")
    int delete(@Param("enterpriseId") Integer enterpriseId, @Param("engineerId") Integer engineerId);

    @Select("select enterprise_id from core_enterprise_engineer where engineer_id = #{engineerId} order by enterprise_id limit 1")
    Integer getOneByEngineerId(@Param("engineerId") Integer engineerId);

    @Select("select ce.* from core_enterprise ce left join core_enterprise_engineer cee on cee.enterprise_id = ce.id where engineer_id = #{engineerId}")
    List<CoreEnterprise> getEnterpriseList(@Param("engineerId") Integer engineerId);
}
